package com.hp.attendance.service;

import com.hp.attendance.dao.AttendanceDao;
import com.hp.attendance.entity.Attendance;
import com.hp.attendance.entity.History;
import com.hp.attendance.entity.PageInfo;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class AttendanceService {

    private AttendanceDao attendanceDao=new AttendanceDao();

    public void addStartAttend(Attendance att) throws SQLException, IOException, ClassNotFoundException {
           attendanceDao.addStartAttend(att);
    }

    public void addEndAttend(Attendance att) throws SQLException, IOException, ClassNotFoundException {
           attendanceDao.addEndAttend(att);

    }
    public List<Attendance> attendance(int employee_number) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
           return attendanceDao.attendance(employee_number);
    }
    public PageInfo<Attendance> getPage(int employee_number,int pageNo , int pageSize) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        PageInfo<Attendance> page = new PageInfo<Attendance>();
        //查询分页的数据                           2       10
        List<Attendance> list = attendanceDao.getLimitList(employee_number,pageNo, pageSize);
        page.setRecords(list);
        //查询总记录条数
        long total = attendanceDao.getTotal(employee_number);
        page.setTotal(total);
        //设置当前页码
        page.setCurrent(pageNo);
        //设置总页数
        int pages = (int)Math.ceil(total / (pageSize * 1.0));
        page.setPages(pages);
        return page;
    }
    public List<Attendance> queryAttList() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException {
        List<Attendance> list = attendanceDao.queryAttList();
        return list;


    }
    public Attendance queryAttByNumDay(int empNum,String day) throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, IOException {
        return attendanceDao.queryAttByNumDay(empNum,day);


    }

    public void updateAtt(int empNum,String day) throws SQLException, IOException, ClassNotFoundException {
        attendanceDao.updateAtt(empNum,day);

    }


}
